package org.paysim.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.AlipayConstants;
import com.alipay.api.DefaultAlipayClient;

import jakarta.annotation.Resource;

@Configuration
public class PayConfig {
    @Resource
    private Environment config;

    @Bean
    public AlipayClient alipayClient() throws AlipayApiException {
        AlipayConfig alipayConfig = new AlipayConfig();
        alipayConfig.setServerUrl(config.getProperty("alipay.gateway-url"));
        alipayConfig.setAppId(config.getProperty("alipay.app-id"));
        alipayConfig.setPrivateKey(config.getProperty("alipay.appPrivateKey"));
        alipayConfig.setFormat(AlipayConstants.FORMAT_JSON);
        alipayConfig.setAlipayPublicKey(config.getProperty("alipay.alipayPublicKey"));
        alipayConfig.setCharset(AlipayConstants.CHARSET_UTF8);
        alipayConfig.setSignType(AlipayConstants.SIGN_TYPE_RSA2);
        return new DefaultAlipayClient(alipayConfig);
    }

}
